package com.cea.papyrus.core.figures;


import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;

import com.cea.papyrus.core.PapyrusPlugin;

/**
 * Property Figure
 * @author Patrick Tessier
 */
public class TemplateParameterFigure extends LabelFigure {
	//constant
//	protected static String _public=" +";
//	protected static String _protected=" #";
//	protected static String _private=" -";
//	protected static String _package="~";
//	protected static String _derived="/";
//	protected static String _ordered="ordered";
//	protected static String _readonly="readOnly";
//	protected static String _subsets="subsets";
//	protected static String _redefines="redefine";
//	protected static String _unique="unique";
//	protected static String _union="union";
//
//
//	protected Label label=new Label();
//	protected String visibility=_public;
//	protected String name="";
//	protected String type="<undefined>";
//	protected String derived="";
//	protected String defaultValue="";
//	protected String multiplicity="";
//	protected String propModifier="";
//	protected boolean isStatic=false;
//	protected String stereotypes="";


	public TemplateParameterFigure()
	{
		FontData[] font={new FontData("Arial", 9, SWT.NORMAL)};
		setFont(PapyrusPlugin.fontManager.get(font));
		setLabelAlignment(PositionConstants.LEFT );
	}

	/**
	 * update property label
	 * @param newText
	 */
	public void display(String newText) {
		//setText(stereotypes+newText);
		setText(newText);
	}

	/**
	 * to add stereotypes
	 * @param name of the operation
	 */
	@Override
	public void setStereotypes(String st){
//		if (st==null) {
//			this.stereotypes="";
//		} else {
//			this.stereotypes=PapyrusPlugin.ST_LEFT+st+PapyrusPlugin.ST_RIGHT;
//		}
		display();
	}

	/**
	 * display the name of the property
	 * @param name of the property
	 */
	@Override
	public void setName(String name){
//		this.name=name;
//		setText(visibility+" "+name);
		display();
	}

	/**
	 * display the type of the property
	 * @param type of the property
	 */
	public void setType(String type){
//		this.type=": "+type;
		display();
	}
	/**
	 * Display default value
	 * @param the default value
	 */
	public void setDefaultValue(String value){
//		if (value!=null)
//		{this.defaultValue="= "+value;} else {
//			value="";
//		}

		display();
	}

	/**
	 * to indicate if the propety is derived
	 * @param b , true the property is derived, false other
	 */
	public void setDerived(boolean b){
//		if (b) {
//			derived=" "+_derived;
//		} else {
//			derived="";
//		}
		display();
	}
	/**
	 * to indicate information about property as unique...
	 * @param unique, true if unique
	 * @param readOnly, true if readonly
	 * @param ordered, true, if ordered
	 * @param isUnion, true if union
	 */
	public void setProperty(boolean unique,boolean readOnly,boolean ordered,boolean isUnion){
//		if (!unique &&!readOnly &&!ordered &&!isUnion) {
//			propModifier="";
//		} else{
//			propModifier=" {";
//			if (readOnly) {
//				propModifier=propModifier+_readonly+", ";
//			}
//			if	(isUnion) {
//				propModifier=propModifier+_union+", ";
//			}
//			if (ordered) {
//				propModifier=propModifier+_ordered+", ";
//			}
//			if (unique) {
//				propModifier=propModifier+_unique+", ";
//			}
//			propModifier=propModifier.substring(0, propModifier.length()-2)+"}";
			display();
//		}
	}


	/**
	 * diplay the property
	 *
	 */
	protected void display(){
//		setText(visibility+derived+" "+name+type+multiplicity+ defaultValue+propModifier);
		setText("toto");
	}

	/**
	 * diplay the property
	 *
	 */
	public String getDisplay(){
//		return visibility+derived+" "+name+type+multiplicity+ defaultValue+propModifier;
		return "toto" ;
	}
	/**
	 * display the multiplicity
	 * @param lower integer
	 * @param upper integer
	 */
	public void setMultiplicity(int lower, int upper){
//		if((lower==1) && (upper==1)){
//			multiplicity="";
//		}
//		else{
//			multiplicity="["+lower+"..";
//			if (upper==-1)
//			{multiplicity=multiplicity+"*]";}
//			else{
//				multiplicity=multiplicity+upper+"]";
//			}
//
//		}
		display();
	}
	/**
	 * display as private
	 *
	 */
	public void setPrivate(){
//		this.visibility=_private;
		display();
	}
	/**
	 * display as protected
	 *
	 */
	public void setProtected(){
//		this.visibility=_protected;
		display();
	}
	/**
	 * display as public
	 *
	 */
	public void setPublic(){
//		this.visibility=_public;
		display();
	}
	/**
	 * display as package
	 *
	 */
	public void setPackage(){
//		this.visibility=_package;
		display();
	}

	/**
	 * display the operation as abstract
	 * @param b true for abstract; false other
	 */
	public void setAbstract(boolean b){
		if (b){
			FontData[] font={new FontData("Arial", 9, SWT.ITALIC)};
			this.setFont(PapyrusPlugin.fontManager.get(font));
		}
		else{
			FontData[] font={new FontData("Arial", 9, SWT.NORMAL)};
			this.setFont(PapyrusPlugin.fontManager.get(font));
		}
	}
	/**
	 *display the element as static
	 * @param b
	 */
	public void setStatic(boolean b){
//		this.isStatic=b;
	}
	/**
	 * paint the label
	 */
	@Override
	public void paint (Graphics graphics) {
		super.paint (graphics);
		Rectangle rect;
		rect = this.getBounds();
//		if (isStatic){
//			graphics.setBackgroundColor(ColorConstants.black);
//			Dimension labelSize=calculateTextSize();
//			graphics.drawLine(rect.x+2, rect.y+rect.height-2, rect.x+labelSize.width, rect.y+rect.height-2); //separator between compartement
//		}
	}
}
